import { useEffect } from 'react';
import req from '../../utils/req';
import api from '../../api';
import { Table } from 'antd';
import useSetState from '../../hooks/useSetState';

const Tables = () => {
  const [{ list }, setState] = useSetState({
    list: [],
  });
  useEffect(() => {
    req.post(api.sys.tables).then((data) => {
      setState({ list: data });
    });
  }, [setState]);
  const columns = [
    { title: '表名称', dataIndex: 'tableName', key: 'tableName' },
    { title: '表描述', dataIndex: 'tableComment', key: 'tableComment' },
    { title: '操作', dataIndex: '_action', key: '_action' },
  ];
  useEffect(() => {
    const obj = {};
    const handler = {
      get(target: Record<string, any>, property: string): any {
        if (property === 'value') {
          const path = '/' + target.path.join('/');
          target.path = [];
          return path;
        }
        target.path = target.path ? target.path.concat(property) : [property];
        return new Proxy(obj, handler);
      },
    };
    const api = new Proxy(obj, handler);
    const a = api.hello.world.geen.name.value;
    const b = api.zz.yy.dd.xx.value;
  }, []);
  return <Table rowKey="tableName" dataSource={list} columns={columns}></Table>;
};

export default Tables;
